function reallocMotionType(p,n)
  use derived
  implicit none

  type(MotionType),pointer,dimension(:) :: &
       reallocMotionType,p
  integer,intent(in) :: n
  integer :: i,nold,ierr

  allocate(reallocMotionType(1:n),stat=ierr)
  if (ierr.ne.0) call abnormal_stop("reallocMotionType",&
       "Memory allocation cause an error.")

  if (.not.associated(p)) return

  nold=n-1
  do i=1,nold
     reallocMotionType(i)%group_no=p(i)%group_no
     reallocMotionType(i)%motion_type=p(i)%motion_type
  end do

  deallocate(p)

  return

end function reallocMotionType
